package 华为面试;

import javax.xml.transform.Source;
import java.util.Scanner;

/**
 @author fujiangnan
 @create 2021-09-28-08-26
 @desc ...
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s1 = "abcd";
        String s2 = "bcdf";
        int maxConst = 3;

        String s3 = "zbcd";
        String s4 = "acde";
        int maxConst2 = 1;

        int ans = method(s1, s2, maxConst);
        int ans2 = method(s3, s4, maxConst2);
        System.out.println(ans);
        System.out.println(ans2);
    }

    public static int method(String s1, String s2, int maxConst) {
        int n = s1.length();
        int start = 0;
        int end = 0;
        int sum = 0;
        int res = 0;
        while (start <= end && end < n) {
            sum += Math.abs(s1.charAt(end) - s2.charAt(end));
            while (sum > maxConst) {
                sum -= Math.abs(s1.charAt(start)-s2.charAt(start));
                ++start;
            }
            res = Math.max(res, end-start+1);
            ++end;
        }
        return res;
    }
}
